﻿@model IEnumerable<MVC_No05.Models.Task>

@{
    ViewBag.Title = "Index";
}

<h2>添加</h2>

<p>
    @Html.ActionLink("添加", "Create")
</p>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.TaskPriority)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Content)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.AddTime)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.TaskState)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.FinishedTime)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.uid)
        </th>
        <th></th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.TaskPriority)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Content)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.AddTime)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.TaskState)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.FinishedTime)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.uid)
            </td>
            <td>
                <button onclick="DeleteBut(@item.TaskID)" class="btn btn-info">删除</button>
                <button onclick="XiangQing(@item.TaskID)" class="btn btn-info">详情</button>
                <button onclick="Update(@item.TaskID)" class="btn btn-info">修改</button>
            </td>
        </tr>
    }

</table>
@section scripts{
    <script src="~/Scripts/jquery-3.4.1.js"></script>
    <script>
        function DeleteBut(id) {
            if (confirm("确定要删除吗?")) {
                $.post("/MyHome/Delete", { uid: id }, function (data) {
                    switch (data) {
                        case 1:
                            location = "/MyHome/Index";
                            break;
                        case 0:
                            console.log("删除失败");
                            break;
                    }
                })
            }
        }

        function XiangQing(id) {
            location = "/MyHome/XiangQing?uid=" + id;
        }

        function Update(id) {
            location = "/MyHome/Update?uid=" + id;
        }
    </script>
}
